import axios from "axios"
import store from "@/store"
const request = axios.create({
    baseURL : process.env.VUE_APP_API,
    timeout: 5000,
    headers:{}
})

request.interceptors.request.use((config)=>{

    config.headers.userTempId = store.state.User.userTempId
    config.headers.token = store.state.User.token
    // console.log(config);
    
    return config
})

request.interceptors.response.use(
    (response)=>{
        if(response.data.code !== 200 && response.data.code !== 20000){
            // alert(response.data.message)
            console.log(response.data.message);
            
            return Promise.reject({message:response.data.message})
        }else{
            return response.data.data
        }
    },
    (error)=>{
        return Promise.reject(error)
    }
)

export default request